home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7797 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Generating pointer to struct from string
  5. Date: 28 Feb 1996 23:51:14 GMT
  6. Organization: OpenVision
  7. Message-ID: <4h2ppi$6pb@spanky.pls.ov.com>
  8. References: <4grk4g$hep@fmsu03.fm.intel.com>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article hep@fmsu03.fm.intel.com, vdalvi@mcd.intel.com (Vishram Dalvi) writes:
  13. >Hello,
  14. >
  15. >Say I have 3 structs aaa, bbb and ccc of type foo:
  16. >
  17. >struct foo {
  18. >    int flag;
  19. >    char name[30]
  20. >} aaa, bbb, ccc;
  21. >
  22. >I assign some values to the data members of all 3 structs. Now I prompt the
  23. >user for the name of one of these structs. I read in the user entry into a
  24. >char array. Assume that the user entered "aaa". How can I generate a pointer
  25. >to the struct "aaa" from the user entry?
  26. >I do not want a switch/case table (if user entered "aaa", access members of
  27. >"aaa", if user entered "bbb"...).
  28. >How do I cast a string into a struct address??
  29. >Thanks in advance,
  30. >
  31. >Vishram Dalvi
  32. >(vdalvi@mcd.intel.com)
  33. >
  34.  
  35.  
  36. At run time, all labels are converted into memory locations.  There is no
  37. relationship to the structure name (except through the symbol table [if present],
  38. but the symbol table is *very* implementation dependent).
  39.  
  40. My best suggestion is to make a lookup table consisting of name strings and
  41. appropriate pointers.  Thus you can search through the table looking for a
  42. string match.
  43.  
  44.             Fletcher.Glenn@ov.com
  45.  
  46.  
  47.